Skip to content

syntax.md: support multiple if-guards on same line #11215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 13, 2021

Conversation

unkarjedy
Copy link
Contributor

@unkarjedy unkarjedy commented Jan 26, 2021

Consider the example:

for {
  x <- 1 to 5
  if true if true
} yield x

Note, that multiple if guards start from a new line and are not separated with a semicolon or a new line.
This code is compiled ok in Scala 3 and is a valid code according to Scala 2 syntax reference:
(though looks like there is a bug in implementation scala/bug#12323)

But it's not supported according to the Scala 3 syntax reference.

related issues:
scala/bug#12323
https://youtrack.jetbrains.com/issue/SCL-13220

@SethTisue
Copy link
Member

To evaluate this, I would like to understand how the Scala 3 spec came to differ from the Scala 2 spec on this point. Who did that when, and why? Was it done on purpose, or could be accidental fallout from some sort of refactoring?

@odersky
Copy link
Contributor

odersky commented Jan 27, 2021

To evaluate this, I would like to understand how the Scala 3 spec came to differ from the Scala 2 spec on this point. Who did that when, and why? Was it done on purpose, or could be accidental fallout from some sort of refactoring?

The Scala-2 syntax reads

Generator ::=  Pattern1 ‘<-’ Expr {[semi] Guard | semi Pattern1 ‘=’ Expr}

I believe the intention was that the optional semicolon before a Guard should be dropped, and that caused the refactoring in Scala 3. But now I see it's not so simple, since semis are also inserted by newlines. So I think it is better to go back to Scala 2's syntax here.

@unkarjedy Can you make the change here, and also in docs/docs/reference/syntax.md, and also in the Parser? We do keep the syntax in several places. Their meaning is as follows:

  • internals/syntax.md Syntax with internal trees, and experimental additions supported by the Parser
  • reference/syntax.md Official language syntax
  • Parser.scala Syntax serves as documentation for parsing methods.

The three syntaxes should be kept in sync.

Consider the example:
```scala
for {
  x <- 1 to 5
  if true; if true; if true
} yield x
```
Note, that multiple if guards start from a new line and are not separated with a semicolon or a new line.
This code is compiled ok in Scala 3 and is a valid code according to Scala 2 syntax reference:
(though looks like there is a bug in implementation scala/bug#12323)

But it's not supported according to the Scala 3 syntax reference.

related issues:
scala/bug#12323
https://youtrack.jetbrains.com/issue/SCL-13220
@unkarjedy
Copy link
Contributor Author

updated

@bishabosha bishabosha requested review from odersky and bishabosha July 8, 2021 18:54
@bishabosha bishabosha self-assigned this Jul 8, 2021
Copy link
Member

@bishabosha bishabosha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly good, thank you, however the AST nodes should only appear in the internals reference

unkarjedy and others added 2 commits July 15, 2021 14:17
Co-authored-by: Jamie Thompson <bishbashboshjt@gmail.com>
Co-authored-by: Jamie Thompson <bishbashboshjt@gmail.com>
@unkarjedy
Copy link
Contributor Author

Merged the changes

As I understand there is an option to "Squash and Merge" directly in Github, so do I need to manually squash the commits?

@unkarjedy unkarjedy requested a review from bishabosha July 15, 2021 11:22
@anatoliykmetyuk
Copy link
Contributor

@bishabosha What's the status of this PR? Can we merge it?

@odersky odersky merged commit d3a26e2 into scala:master Oct 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants